package com.yeci.utils;

import java.security.MessageDigest;

/**
 * 自定义 Md5 + salt 生成加密密码的工具类
 *
 * @author: yeci
 * @date: 2021/9/2 13:29
 **/
public class SaSecureUtil {
  public static String md5(String str) {
    str = str == null ? "" : str;
    char[] hexDigits = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

    try {
      byte[] btInput = str.getBytes();
      MessageDigest mdInst = MessageDigest.getInstance("MD5");
      mdInst.update(btInput);
      byte[] md = mdInst.digest();
      int j = md.length;
      char[] strA = new char[j * 2];
      int k = 0;
      byte[] var8 = md;
      int var9 = md.length;

      for(int var10 = 0; var10 < var9; ++var10) {
        byte byte0 = var8[var10];
        strA[k++] = hexDigits[byte0 >>> 4 & 15];
        strA[k++] = hexDigits[byte0 & 15];
      }

      return new String(strA);
    } catch (Exception var12) {
      return var12.getMessage();
    }
  }

  public static String md5BySalt(String str, String salt) {
    return md5(md5(str) + md5(salt));
  }
}
